package com.xiaoxi.exam.dao;

import com.xiaoxi.exam.model.User;
import com.xiaoxi.exam.model.UserExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface UserMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_user.t_user
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    long countByExample(UserExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_user.t_user
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int deleteByExample(UserExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_user.t_user
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Update({
        "update s_user.t_user",
        "set deleted_at = now()",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_user.t_user
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Select({
        "insert into s_user.t_user (source, ",
        "status, ",
        "tel, temp_tel, verify_code, ",
        "password, openid, ",
        "code, created_at, ",
        "updated_at, deleted_at, ",
        "nick_name, avatar)",
        "values (#{source,jdbcType=SMALLINT,typeHandler=com.xiaoxi.exam.mybatis.typehandlers.EnumCodeHandler}, ",
        "#{status,jdbcType=SMALLINT,typeHandler=com.xiaoxi.exam.mybatis.typehandlers.EnumCodeHandler}, ",
        "#{tel,jdbcType=VARCHAR}, #{tempTel,jdbcType=VARCHAR}, #{verifyCode,jdbcType=VARCHAR}, ",
        "#{password,jdbcType=VARCHAR}, #{openid,jdbcType=VARCHAR}, ",
        "#{code,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, ",
        "#{updatedAt,jdbcType=TIMESTAMP}, #{deletedAt,jdbcType=TIMESTAMP}, ",
        "#{nickName,jdbcType=VARCHAR}, #{avatar,jdbcType=VARCHAR})", 
        " returning id"
    })
    @Options(useGeneratedKeys=true,keyProperty="id")
    long insertReturningId(User record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_user.t_user
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Insert({
        "insert into s_user.t_user (source, ",
        "status, ",
        "tel, temp_tel, verify_code, ",
        "password, openid, ",
        "code, created_at, ",
        "updated_at, deleted_at, ",
        "nick_name, avatar)",
        "values (#{source,jdbcType=SMALLINT,typeHandler=com.xiaoxi.exam.mybatis.typehandlers.EnumCodeHandler}, ",
        "#{status,jdbcType=SMALLINT,typeHandler=com.xiaoxi.exam.mybatis.typehandlers.EnumCodeHandler}, ",
        "#{tel,jdbcType=VARCHAR}, #{tempTel,jdbcType=VARCHAR}, #{verifyCode,jdbcType=VARCHAR}, ",
        "#{password,jdbcType=VARCHAR}, #{openid,jdbcType=VARCHAR}, ",
        "#{code,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, ",
        "#{updatedAt,jdbcType=TIMESTAMP}, #{deletedAt,jdbcType=TIMESTAMP}, ",
        "#{nickName,jdbcType=VARCHAR}, #{avatar,jdbcType=VARCHAR})"
    })
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insert(User record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_user.t_user
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    long insertSelectiveReturningId(User record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_user.t_user
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int insertSelective(User record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_user.t_user
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    List<User> selectByExample(UserExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_user.t_user
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Select({
        "select",
        "id, source, status, tel, temp_tel, verify_code, password, openid, code, created_at, ",
        "updated_at, deleted_at, nick_name, avatar",
        "from s_user.t_user",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("com.xiaoxi.exam.dao.UserMapper.BaseResultMap")
    User selectByPrimaryKey(Long id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_user.t_user
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_user.t_user
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int updateByExample(@Param("record") User record, @Param("example") UserExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_user.t_user
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int updateByPrimaryKeySelective(User record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_user.t_user
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Update({
        "update s_user.t_user",
        "set source = #{source,jdbcType=SMALLINT,typeHandler=com.xiaoxi.exam.mybatis.typehandlers.EnumCodeHandler},",
          "status = #{status,jdbcType=SMALLINT,typeHandler=com.xiaoxi.exam.mybatis.typehandlers.EnumCodeHandler},",
          "tel = #{tel,jdbcType=VARCHAR},",
          "temp_tel = #{tempTel,jdbcType=VARCHAR},",
          "verify_code = #{verifyCode,jdbcType=VARCHAR},",
          "password = #{password,jdbcType=VARCHAR},",
          "openid = #{openid,jdbcType=VARCHAR},",
          "code = #{code,jdbcType=VARCHAR},",
          "created_at = #{createdAt,jdbcType=TIMESTAMP},",
          "updated_at = #{updatedAt,jdbcType=TIMESTAMP},",
          "deleted_at = #{deletedAt,jdbcType=TIMESTAMP},",
          "nick_name = #{nickName,jdbcType=VARCHAR},",
          "avatar = #{avatar,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(User record);
}